package io.renren.modules.pms.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.renren.modules.pms.entity.ProductCategoryAttributeRelationEntity;
import io.renren.modules.pms.entity.dto.RelationAttrInfoByCidDTO;
import io.renren.modules.pms.service.impl.ProductAttributeServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.pms.entity.ProductAttributeEntity;
import io.renren.modules.pms.service.ProductAttributeService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 *
 *
 * @author LuoShun
 * @email lori6166@163.com
 * @date 2021-11-26 16:49:29
 */
@Api(tags  = "商品类型属性管理")
@RestController
@RequestMapping("productAttribute")
public class ProductAttributeController {
    @Autowired
    private ProductAttributeService productAttributeService;

    /**
     * 分页获取属性列表
     */
    @ApiOperation("分页获取属性列表")
    @GetMapping("/list/{cid}")
    @RequiresPermissions("pms:productattribute:list")
    public R list(
            @PathVariable long cid,
            @RequestParam Map<String, Object> params){
        PageUtils page = productAttributeService.queryPage(params,cid);


        return R.ok().put("page", page);
    }


    /**
     * 根据id获取商品属性
     */
    @ApiOperation("根据id获取商品类型")
    @GetMapping("/{id}")
    @RequiresPermissions("pms:productattribute:info")
    public R info(@PathVariable("id") Long id){
		ProductAttributeEntity productAttribute = productAttributeService.getById(id);

        return R.ok().put("data", productAttribute);
    }

    /**
     * 添加商品属性
     */
    @ApiOperation("添加商品属性")
    @PostMapping("/create")
    @RequiresPermissions("pms:productattribute:save")
    public R save(@RequestBody ProductAttributeEntity productAttributeEntity){
		productAttributeService.creat(productAttributeEntity);

        return R.ok();
    }

    /**
     * 修改商品属性
     */
    @ApiOperation("修改商品属性")
    @PostMapping("/update/{id}")
    @RequiresPermissions("pms:productattribute:update")
    public R update(@RequestBody ProductAttributeEntity productAttribute){
		productAttributeService.updateById(productAttribute);

        return R.ok();
    }

    /**
     * 删除商品属性
     */
    @ApiOperation("删除商品属性")
    @PostMapping("/delete")
    @RequiresPermissions("pms:productattribute:delete")
    public R delete(@RequestBody Map<String, Object> map){
        productAttributeService.delete(map);

        return R.ok();
    }

    /**
     * 根据商品分类id获取筛选属性信息
     */
    @ApiOperation("根据商品分类id获取筛选属性信息")
    @GetMapping("/attrInfo/{cId}")
    @RequiresPermissions("pms:productattribute:attrInfo")
    public R getRelationAttrInfoByCid(@PathVariable("cId") Long productCategoryId){
        List<RelationAttrInfoByCidDTO> list = productAttributeService.getRelationAttrInfoByCid(productCategoryId);

        return R.ok().put("data", list);
    }

}
